﻿// ===============================================================================
// XCI.NET 西安交通信息WinForm开发框架 2018 版权所有
// ===============================================================================
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using XCI.Data.Entity;

namespace XCI.Data
{
    public interface IDbProvider
    {
        /// <summary>
        /// 获取数据对象创建工厂
        /// </summary>
        /// <returns></returns>
        DbProviderFactory GetDbProviderFactory();

        /// <summary>
        /// 获取参数前缀
        /// </summary>
        string GetParamPrefix();

        /// <summary>
        /// 执行命令之前调用,可以修改DbCommand对象
        /// </summary>
        /// <param name="cmd">命令对象</param>
        void BeforeExecute(IDbCommand cmd);

        /// <summary>
        /// 添加游标参数（针对Oracle数据库）
        /// </summary>
        /// <param name="param">参数对象</param>
        void SetCursorParam(IDbDataParameter param);

        /// <summary>
        /// 获取Insert语句模板
        /// </summary>
        /// <param name="entityData">实体信息</param>
        /// <param name="cmd">Insert命令对象</param>
        void PrepInsert(EntityData entityData, DbCommand cmd);

        /// <summary>
        /// 获取分页语句模板
        /// </summary>
        /// <param name="sql">查询语句</param>
        /// <param name="orderBy"></param>
        /// <param name="startIndex"></param>
        /// <param name="endIndex"></param>
        /// <returns>获取分页语句模板</returns>
        string GetPageStatement(string sql, string orderBy, int startIndex, int endIndex);

        /// <summary>
        /// Builds an SQL query suitable for performing page based queries to the database
        /// </summary>
        /// <param name="skip">The number of rows that should be skipped by the query</param>
        /// <param name="take">The number of rows that should be retruend by the query</param>
        /// <param name="parts">The original SQL query after being parsed into it's component parts</param>
        /// <returns>The final SQL query that should be executed.</returns>
        string BuildPageQuery(long skip, long take, PagingHelper.SQLParts parts);
    }
}
